﻿<!DOCTYPE html>

<html>

<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    @Scripts.Render("~/Resource/js/fe.head.js")
</head>

<body>
    <div id="app" v-cloak>
        <el-container class="list_pagecontainer">
            <el-aside width="200px">
                <div>
                    <common-tree :tree-data="treeData" :tree-body-height="treeHeight" v-on:tree-node-click="nodeClick">
                    </common-tree>
                </div>
            </el-aside>
            <el-main>
                <el-container class="list_pagecontainer">
                    <el-header>
                        <el-row>
                            <el-col :span="24">
                                <div class="list_searchcontainer">
                                    登录名：
                                    <el-input placeholder="请输入登录名" v-model="LoginID" class="list_searchinput">
                                    </el-input>
                                    姓名：
                                    <el-input placeholder="请输入姓名" v-model="DisplayName" class="list_searchinput">
                                    </el-input>
                                    <el-checkbox v-model="SearchInAll">所有人员</el-checkbox>
                                    <el-button type="primary" v-on:click="bindGrid" icon="el-icon-search">搜索</el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </el-header>
                    <el-main>
                        <common-table :data="tableData" :page-Index="pageIndex" :page-Size="pageSize" :total="total" :table-Height="tableHeight"
                            :show-Delete="false" v-on:on-load="bindGrid" v-on:handle-edit="edit" v-on:on-pageindexchange="pageIndexChange" ref="table">
                            <template slot="column">
                                <el-table-column prop="DisplayName" header-align="center" align="left" label="姓名" width="100">
                                </el-table-column>
                                <el-table-column prop="LoginID" header-align="center" align="left" label="登录名" width="100">
                                </el-table-column>
                                <el-table-column prop="OUName" header-align="center" align="left" label="所属部门">
                                </el-table-column>
                                <el-table-column prop="Mobile" header-align="center" align="center" label="联系方式" width="110">
                                </el-table-column>
                                <el-table-column prop="OrderNum" header-align="center" align="center" label="排序" width="100">
                                </el-table-column>
                            </template>
                            <template slot="opbefore">
                                <el-table-column prop="OrderNum" header-align="center" align="center" label="初始化密码" width="100">
                                    <template slot-scope="scope">
                                        <el-button type="danger" size="mini" v-on:click="initPWD(scope.row)">初始化密码</el-button>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="OrderNum" header-align="center" align="center" label="修改状态" width="100">
                                    <template slot-scope="scope">
                                        <el-button v-if="scope.row.IsEnable==0" type="danger" size="mini" v-on:click="changeEnable(scope.row)">启用</el-button>
                                        <el-button v-else type="danger" size="mini" v-on:click="changeEnable(scope.row)">禁用</el-button>
                                    </template>
                                </el-table-column>
                            </template>
                        </common-table>
                    </el-main>
                    <el-footer>
                        <el-row>
                            <el-col :span="24">
                                <div class="list_opcontainer">
                                    <el-button type="primary" v-on:click="add">添加部人员</el-button>
                                    <el-button type="danger" v-on:click="batchDelete">删除选中</el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </el-footer>
                </el-container>
            </el-main>
        </el-container>
    </div>
</body>
@Scripts.Render("~/Resource/js/fe.foot.js") @Scripts.Render("~/Resource/component/tree/index.js")

</html>

<script>
    var treeUrl = GetRootPath() + "Frame/OU/Tree"
    var tableUrl = GetRootPath() + "Frame/User/FindList"
    var batchDeletetUrl = GetRootPath() + "Frame/User/OperateBatchDelete"
    var initPWDUrl = GetRootPath() + "Frame/User/InitPWD"
    var changeEnableUrl = GetRootPath() + "Frame/User/ChangeEnable"
    var pageData = {
        //data
        tableData: [],
        treeData: [],
        //page
        pageIndex: 1,
        pageSize: 10,
        total: 0,
        //search
        LoginID: "",
        DisplayName: "",
        //css
        tableHeight: 0,
        treeHeight: 0,
        //otherparams
        OUGuid: 'Top',
        SearchInAll: false
    };
    new Vue({
        el: '#app',
        data: pageData,
        mounted: function () {
            bindTree();
            pageData.tableHeight = CaculateTableHeight();
            pageData.treeHeight = CaculatWindowHeight();
        },
        methods: {
            pageIndexChange:function(val){
                this.pageIndex = val
            },
            bindGrid: function () {
                bindGrid();
            },
            add: function () {
                OpenTopDialog('useradd', '添加人员', 'Frame/User/Add?OUGuid=' + pageData.OUGuid, 600, 800,
                    bindGrid)
            },
            edit: function (index, row) {
                OpenTopDialog('useredit', '编辑人员', 'Frame/User/Edit?RowGuid=' + row.RowGuid, 600, 800,
                    bindGrid)
            },
            batchDelete: function () {
                var selectRow = this.$refs.table.getSelectRow();
                if (selectRow.length == 0) {
                    OpenWaring('提示', '请选择删除的数据')
                } else {
                    OpenConfirm('提示', '确认删除选中的数据？', function () {
                        var KeyGuidList = "";
                        selectRow.forEach(element => {
                            KeyGuidList += element.RowGuid + ";";
                        });
                        var data = {
                            KeyGuidList: KeyGuidList
                        }
                        JsonAjaxPost(batchDeletetUrl, JSON.stringify(data), function (data,
                            status) {
                            if (data.code == 0) {
                                OpenSuccess('提示', '删除成功！', bindGrid)
                            } else {
                                OpenFail('提示', '删除失败！')
                            }
                        })
                    })
                }
            },
            nodeClick: function (data, checked, node) {
                pageData.OUGuid = data.id
                bindGrid();
            },
            initPWD: function (row) {
                var data = {
                    RowGuid: row.RowGuid
                }
                JsonAjaxPost(initPWDUrl, JSON.stringify(data), function (data,
                    status) {
                    if (data.code == 0) {
                        OpenSuccess('提示', '初始化成功', bindGrid)
                    } else {
                        OpenFail('提示', '初始化失败')
                    }
                })
            },
            changeEnable: function (row) {
                if(row.IsEnable==0){
                    row.IsEnable = 1
                }else{
                    row.IsEnable = 0
                }
                var data = {
                    RowGuid: row.RowGuid,
                    Enable: row.IsEnable
                }
                JsonAjaxPost(changeEnableUrl, JSON.stringify(data), function (data,
                    status) {
                    if (data.code == 0) {
                        if (row.Enable == 0) {
                            OpenSuccess('提示', '禁用成功', bindGrid)
                        } else {
                            OpenSuccess('提示', '启用成功', bindGrid)
                        }

                    } else {
                        if (row.Enable == 0) {
                            OpenFail('提示', '禁用失败')
                        } else {
                            OpenFail('提示', '启用失败')
                        }

                    }
                })
            }

        }
    })

    function bindGrid() {
        var data = {
            PageIndex: pageData.pageIndex,
            PageSize: pageData.pageSize,
            LoginID: pageData.LoginID,
            DisplayName: pageData.DisplayName,
            OUGuid: pageData.OUGuid,
            SearchInAll: pageData.SearchInAll
        }
        JsonAjaxPost(tableUrl, JSON.stringify(data), function (data, status) {
            Vue.set(pageData, "tableData", data.data);
            Vue.set(pageData, "total", data.total)
        })
    }

    function bindTree() {
        var data = {

        }
        JsonAjaxPost(treeUrl, JSON.stringify(data), function (data, status) {
            Vue.set(pageData, "treeData", data.tree);
        })
    }
</script>